home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / t1 / t1-config.frm.z / t1-config.frm
Encoding:
Text File  |  2002-06-12  |  10.3 KB  |  413 lines

  1. #!/usr/bin/perl5
  2. #
  3. # t1.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: t1-config.frm,v 1.32 1997/11/17 19:10:38 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $confW = "/etc/config/wsyncd.options";
  26. $dummy = "/etc/config/wsyncd.options.tmp";
  27. $confDev = "/etc/uucp/Devices";
  28. $confSys = "/etc/uucp/Systems";
  29.  
  30. $myname = "t1-config.cgi";
  31. $help_page = "t1-config-help.html";
  32. $title = "T1 Configuration";
  33.  
  34. $js = 
  35. "$js_standard
  36. $js_error_box
  37. $js_help
  38. $js_hostname
  39. function checkForm(form) {
  40.     if (!testHostname(form.nme, form.nme.value, \"connection name\", 0)) return (false);
  41.     return (true);
  42. }";
  43.  
  44. print "Content-type: text/html\n\n";
  45.  
  46. &get_fields;
  47.  
  48. &getCurrentStatus;
  49.  
  50. $help = $document_root . $ENV{"SCRIPT_NAME"};
  51. $help =~ s/cgi$/hlp/;
  52. exec $help if ($fld{'help'} eq "Help");
  53.  
  54. if ($fld{'doit'} eq 'Ok') {
  55.     if ($fld{'enable'} eq 'Yes') { &formValidation; }
  56.     if ($fld{'port'} eq 'Port 1') { 
  57.     $portOn = 0;
  58.     $portOff = 1; 
  59.     }
  60.     else { 
  61.     $portOn = 1;
  62.     $portOff = 0; 
  63.     }
  64.  
  65.     if ($fld{'enable'} eq 'Yes') { 
  66.         &turnOnPort($portOn);
  67.         &turnOffPort($portOff);
  68.     system("/etc/chkconfig", "wsyncd", "on");
  69.         system("/etc/init.d/wsync stop > /dev/null 2>&1");
  70.         system("/etc/init.d/wsync start > /dev/null 2>&1");
  71.         &handleSystems;
  72.         &handleDevices($portOn);
  73.         $message = "$fld{'port'} enabled."; 
  74.     } else {
  75.         &turnOffPort(0);
  76.         &turnOffPort(1);
  77.     system("/etc/chkconfig", "wsyncd", "off");
  78.         system("/etc/init.d/wsync stop > /dev/null 2>&1");
  79.         $message = "T1 disabled";
  80.     }
  81.     if (!$message) { $message = "No change."; }
  82.  
  83.     &getCurrentStatus;
  84. } elsif ($fld{'port'}) { $message = qq|Use "Ok" button to submit form.|; }
  85.  
  86. &generic;
  87.  
  88. sub formValidation {
  89.     &error("Invalid host name.") if &check_login($fld{'nme'});
  90. }
  91.  
  92. sub error {
  93.     &error_block($_[0]);
  94.     &generic;
  95.     exit 0;
  96. }
  97.  
  98. sub handleDevices {
  99.     $rename = 0;
  100.     $found = 0;
  101.     $dname = "/dev/gsc/wsty0".$_[0];
  102.     open(IN,"< $confDev");
  103.     open(OUT,"> $dummy");
  104.     while(<IN>) {
  105.     @items = split(/\s+/);
  106.     if ($items[0] ne 'WAN') { print OUT $_; next; }
  107.     if ($items[1] ne $dname) {
  108.         print OUT "# $_";
  109.         $rename = 1;
  110.         $found = 1;
  111.         print OUT qq|WAN $dname - - direct\n|;
  112.     } else { print OUT $_; $found = 1; }
  113.     }
  114.     if (!$found) {
  115.     print OUT qq|WAN $dname - - direct\n|;
  116.     $rename = 1;
  117.     }
  118.     close(IN);
  119.     close(OUT);
  120.     if ($rename) { rename($dummy,$confDev); }
  121. }    
  122.     
  123.  
  124. sub handleSystems {
  125.     $rename = 0;
  126.     $found = 0;
  127.     open(IN,"< $confSys");
  128.     open(OUT,"> $dummy");
  129.     while(<IN>) {
  130.     @items = split(/\s+/);
  131.     if ($items[2] ne 'WAN') { print OUT $_; next; }
  132.     if ($items[0] ne $fld{'nme'}) {
  133.         print OUT "# $_";
  134.         $rename = 1;
  135.         $found = 1;
  136.         print OUT qq|$fld{'nme'} Any WAN - "" "" PPP CONNECTED\n|;
  137.     } else { print OUT $_; $found = 1; }
  138.     }
  139.     if (!$found) {
  140.     print OUT qq|$fld{'nme'} Any WAN - "" "" PPP CONNECTED\n|;
  141.     $rename = 1;
  142.     }
  143.     close(IN);
  144.     close(OUT);
  145.     chmod 600, $confSys;
  146.     if ($rename) { rename($dummy,$confSys); }
  147.     chmod 400, $confSys;
  148. }    
  149.  
  150. sub turnOffPort {
  151.     $nm = $_[0];
  152.  
  153.     undef @terms;
  154.     $terms[0] = 'wan0'.$nm;
  155.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  156.  
  157.     $terms[0] = 'wstyd0'.$nm;
  158.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  159.  
  160.     $terms[0] = 'wstyd0'.$nm;
  161.     $terms[1] = 'wan0'.$nm;
  162.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  163. }
  164.  
  165. sub turnOnPort {
  166.     $nm = $_[0];
  167.  
  168.     undef @terms;
  169.     $terms[0] = 'wan0'.$nm;
  170.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  171.     elsif (! &lookFor(0,$confW,*terms)) { 
  172.     &writeTop($confW,"wan0".$nm."\td\t\t/dev/gsc/wan0".$nm); 
  173.     }
  174.  
  175.     $terms[0] = 'wstyd0'.$nm;
  176.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  177.     elsif (! &lookFor(0,$confW,*terms)) { 
  178.     &writeTop($confW,"wstyd0".$nm."\t\td\t/dev/gsc/wstyd0".$nm); 
  179.     }
  180.  
  181.     $terms[0] = 'wstyd0'.$nm;
  182.     $terms[1] = 'wan0'.$nm;
  183.     if (&lookFor(1,$confW,*terms)) { 
  184.     &uncomment($confW,*terms); }
  185.     elsif (! &lookFor(0,$confW,*terms)) {
  186.     if ($nm == 0) { $let = "D"; } else { $let = "E"; }
  187.     &writeBottom($confW,"$terms[0]\t\t$terms[1]\tWSYNCD_SNID=$let"); 
  188.     }
  189. }
  190.  
  191. sub writeTop {
  192.     local($file) = $_[0];
  193.     local($value) = $_[1];
  194.     $found = 0;
  195.     open(IN,"< $file");
  196.     open(OUT,"> $dummy");
  197.     while(<IN>) {
  198.     if ($_ eq "%%\n" && $found == 0) {
  199.         $found = 1;
  200.         print OUT "$value\n\n%%\n";
  201.     }
  202.     if ($_ eq "\n" && $found == 0) {
  203.         $found = 1; 
  204.         print OUT "\n$value\n";
  205.     } else { print OUT $_; }
  206.     }
  207.     close(IN);
  208.     close(OUT);
  209.     rename($dummy,$file);
  210. }            
  211.  
  212. sub writeBottom {
  213.     local($file) = $_[0];
  214.     local($value) = $_[1];
  215.     $found = 0;
  216.     open(IN,"< $file");
  217.     open(OUT,"> $dummy");
  218.     while(<IN>) {
  219.     if (substr($_,0,2) eq '%%' && $found == 0) {
  220.         print OUT "%%\n\n$value\n";
  221.         $found = 1;
  222.     } else { print OUT $_; }
  223.     }
  224.     if ($found == 0) { print OUT "$value\n"; }
  225.     close(IN);
  226.     close(OUT);
  227.     rename($dummy,$file);
  228. }
  229.    
  230. sub uncomment {
  231.     local($file) = $_[0];
  232.     local(*values) = @_[1];
  233.     open(IN,"< $file");
  234.     open(OUT,"> $dummy");
  235.     $fix = "fix";
  236.  
  237.     while(<IN>) {
  238.     $line = $_;
  239.     if ($line eq "\n") { print OUT "\n"; next; }
  240.     $fix =~ /(fix)/;
  241.     $line =~ /^\s*\#\s*(\S.*)/;
  242.     $line1 = $1;
  243.     @items = split(/\s+/,$line1);
  244.     $chk = 1;
  245.     for ($ii=0;$ii<=$#values;$ii++) {
  246.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  247.     }
  248.     if ($chk) { print OUT "$line1\n"; }
  249.     else { print OUT $line; }
  250.     }
  251.     close(OUT);
  252.     close(IN);
  253.     rename($dummy,$file);
  254. }
  255.  
  256. sub comment {    
  257.     local($file) = $_[0];
  258.     local(*values) = @_[1];
  259.     open(IN,"< $file");
  260.     open(OUT,"> $dummy");
  261.     while(<IN>) {
  262.     $line = $_;
  263.     if ($line eq "\n") { print OUT "\n"; next; }
  264.     @items = split(/\s+/,$line);
  265.     $chk = 1;
  266.     for ($ii=0;$ii<=$#values;$ii++) {
  267.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  268.     }
  269.     if ($chk) { print OUT "#$line"; }
  270.     else { print OUT $line; }
  271.     }
  272.     close(OUT);
  273.     close(IN);
  274.     rename($dummy,$file);
  275. }
  276.  
  277. sub lookFor {
  278.     local($ii);
  279.     local($mode) = $_[0];
  280.     local($file) = $_[1];
  281.     local(*values) = @_[2];
  282.     open(IN,"< $file");
  283.     while(<IN>) {
  284.     $line = $_;
  285.     if ($mode == 1) {
  286.         $line =~ /^\s*\#\s*(\S.*)/;
  287.         $line1 = $1;
  288.     } else { $line1 = $line; }
  289.     @items = split(/\s+/,$line1);
  290.     $chk = 1;
  291.     for ($ii=0;$ii<=$#values;$ii++) {
  292.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  293.     }
  294.     if ($chk) { close(IN); return 1; }
  295.     }
  296.     close(IN);
  297.     return 0;
  298. }
  299.  
  300. # will check for existence of correct, uncommented lines.  does 
  301. # not check for conflicts with other devices (yet)
  302. # Also checks chkconfig status of wsyncd.
  303. sub getCurrentStatus {
  304.         $wsyncd = "/usr/etc/wsyncd";
  305.  
  306.         if (! -e $wsyncd || !&isT1Board) {
  307.             &title_block($title);
  308.             &header_block($title);
  309.             if (! -e $wsyncd) { 
  310.             $message = "T1 software not installed.  Install subsystems "
  311.                 . "</i><b>wsync.sw.sw</b><i> and </i><b>eoe.sw.dlpi</b><i> "
  312.                 . "from the T1 software CD.</i>"; 
  313.         } else { $message = "T1 hardware not installed."; }
  314.             print "<i>$message</i>";
  315.             exit 0;
  316.         }
  317.  
  318.     $port = "Port 1";
  319.     $enable = 'No';
  320.     for ($i=0;$i<2;$i++) {
  321.     $chw[$i] = &checkWsyncd($i);
  322.     if ($chw[$i]) { 
  323.         $enable = 'Yes';
  324.         if ($i) { $port = "Port 2"; } 
  325.     }
  326. #    else { $enable = 'No'; }
  327.     }
  328.     $ch_opt = &get_config("wsyncd");
  329.     if ($ch_opt eq "No") { $enable = "No"; }
  330.  
  331.     $nme = "";
  332.     open(IN,"< $confSys");
  333.     while(<IN>) {
  334.     @items = split(/\s+/);
  335.     if ($items[2] eq 'WAN') { $nme = $items[0]; }
  336.     }
  337.     close(IN);
  338. }
  339.  
  340. sub isT1Board {
  341.     $ret = 0;
  342.     open(IN,"/usr/bin/hinv | ");
  343.     while(<IN>) {
  344.     @items = split(/\s+/);
  345.     if ($items[0] eq 'GIO') { 
  346.         $ret = 1;
  347.         $last;
  348.     }
  349.     }
  350.     close(IN);
  351.     return $ret;
  352. }
  353.  
  354. # here only check that the line is uncommented
  355. sub checkWsyncd {
  356.     $nm = $_[0];
  357.     $beforePercent = 1;
  358.     $check1 = 0;
  359.     $check2 = 0;
  360.  
  361.     open(IN,"< $confW");
  362.     while(<IN>) {
  363.     $line = $_;
  364.     if (substr($line,0,1) eq '#') { next; }
  365.     if ($line eq "%%\n") {
  366.         if ($check1 == 0 || $check2 == 0) { return 0; }
  367.         $beforePercent = 0; next; }
  368.     @items = split(/\s+/,$line);
  369.  
  370.     if ($beforePercent && $items[0] eq "wan0".$nm) { $check1 = 1; }
  371.     if ($beforePercent && $items[0] eq "wstyd0".$nm) { $check2 = 1; }
  372.     if (!$beforePercent && $items[0] eq 'wstyd0'.$nm) { return 1; }
  373.     }
  374.     close(IN);
  375.     return 0;
  376. }
  377.     
  378. sub generic {
  379.     &js_title_block($title,$js);
  380.     &header_block($title);
  381.  
  382.     print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  383.  
  384.     print "<i>$message</i>";
  385.  
  386.     print "<center><table cellpadding=5 width=450>";
  387.  
  388. #    print "<tr><th></th><th align=left>Port 1</th><th align=left>Port 2</th></tr>";
  389.  
  390. #    print "<tr><th align=left>Enable T1:</th><th align=left>",
  391. #      &radio('enable0',$enable[0],'Yes','No'),
  392. #      "</th><th align=left>",
  393. #      &radio('enable1',$enable[1],'Yes','No'),
  394. #      "</th></tr>";
  395.  
  396.     print qq|<tr><th align=left>Enable T1:</th><th align=left>|,
  397.         &radio("enable",$enable,"Yes","No"),"</th></tr>";
  398.  
  399.     print "<tr><th align=left>Port:</th><th align=left>",
  400.         &radio('port',$port,'Port 1','Port 2'),"</th></tr>";
  401.  
  402.     print "<tr><th align=left>Connection name for remote system:</th>
  403.         <th align=left>",
  404.         &text('nme',$nme,12),"</th></tr>";
  405.  
  406.     print '</table></center><br>';
  407.  
  408.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  409.         "onClick=\"do_help('$help_page'); return (false)\"");
  410.  
  411.     print '</form></body></html>';
  412. }
  413.